/*
 * @Descripttion: 
 * @version: 
 * @Author: 冉勇
 * @Date: 2021-09-08 17:50:09
 * @LastEditTime: 2021-10-21 13:18:30
 */
import Vue from 'vue'
import Router from 'vue-router'
// import Login from '../comments/Login.vue'
// 懒加载路由
const Login = () => import(/* webpackChunkName: "login_home_welcome" */ '../comments/Login.vue')
// import Home from '../comments/Home.vue'
const Home = () => import(/* webpackChunkName: "login_home_welcome" */ '../comments/Home.vue')
// import Welcome from '../comments/Welcome.vue'
const Welcome = () => import(/* webpackChunkName: "login_home_welcome" */ '../comments/Welcome.vue')

// import Users from '../comments/user/Users.vue'
const Users = () => import(/* webpackChunkName: "Users_Rights_Roles" */ '../comments/user/Users.vue')
// import Rights from '../comments/power/Rights.vue'
const Rights = () => import(/* webpackChunkName: "Users_Rights_Roles" */ '../comments/power/Rights.vue')
// import Roles from '../comments/power/Roles.vue'
const Roles = () => import(/* webpackChunkName: "Users_Rights_Roles" */ '../comments/power/Roles.vue')


// import Cate from '../comments/goods/Cate.vue'
const Cate = () => import(/* webpackChunkName: "Cate_Params" */ '../comments/goods/Cate.vue')
// import Params from '../comments/goods/Params.vue'
const Params = () => import(/* webpackChunkName: "Cate_Params" */ '../comments/goods/Params.vue')

// import GoodsList from '../comments/goods/List.vue'
const GoodsList = () => import(/* webpackChunkName: "GoodsList_Add" */ '../comments/goods/List.vue')
// import Add from '../comments/goods/Add.vue'
const Add = () => import(/* webpackChunkName: "GoodsList_Add" */ '../comments/goods/Add.vue')

// import Order from '../comments/order/Order.vue'
const Order = () => import(/* webpackChunkName: "Order_Report" */ '../comments/order/Order.vue')
// import Report from '../comments/report/Report.vue'
const Report = () => import(/* webpackChunkName: "Order_Report" */ '../comments/report/Report.vue')

Vue.use(Router)

const router = new Router({
  mode: 'hash',
  routes: [
    {
      path: '/',
      name: '根目录地址重定向',
      redirect: '/login'
    },
    {
      path: '/login',
      name: '登录页',
      component: Login
    },
    {
      path: '/home',
      name: '主页',
      component: Home,
      redirect: '/welcome',
      children:[
        {
          path: '/welcome',
          name: '欢迎页',
          component: Welcome
        },
        {
          path: '/users',
          name: '用户管理',
          component: Users
        },
        {
          path: '/rights',
          name: '权限列表',
          component: Rights
        },
        {
          path: '/roles',
          name: '角色列表',
          component: Roles
        },
        {
          path: '/categories',
          name: '商品分类',
          component: Cate
        },
        {
          path: '/params',
          name: '分类参数',
          component: Params
        },
        {
          path: '/goods',
          name: '商品列表',
          component: GoodsList
        },
        {
          path: '/goods/add',
          name: '商品添加',
          component: Add
        },
        {
          path: '/orders',
          name: '订单管理',
          component: Order
        },
        {
          path: '/reports',
          name: '数据报表',
          component: Report
        },
      ]
    },
  ]
})

// 挂载路由导航守卫
router.beforeEach((to, from, next) => {
  // to 将要访问的路径
  // from 代表从哪个路径跳转而来
  // next 是一个函数,代表放行
  // next() 放行 next(‘/login’) 强制跳转
  if(to.path === '/login') return next();
  //  获取token
  const tokenStr = window.sessionStorage.getItem('token');
  if (!tokenStr) return next('/login')
  next();
})
export default router